package com.laoda.ikun_food.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class AdminLoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(final HttpServletRequest request,
                             final HttpServletResponse response,
                             final Object handler) throws Exception {
        HttpSession session = request.getSession();
        if(session.getAttribute("admin") == null) {
            response.sendRedirect("/admin/login");
            // 如果是前后端分离
            // response.getWriter().println("You are not logged in");
        }
        return true;
    }


}
